# -*- coding: UTF-8 -*-
"""
@Filename:exerc1.py
@author:Cora
@time:2025-05-09
"""
import requests


def crawl_pxc():
    url = 'http://www.pxc.jx.cn/'  # 官网URL
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
    }
    try:
        # 发送GET请求并设置UA伪装
        response = requests.get(url, headers=headers)
        response.raise_for_status()  # 检查请求是否成功

        # 自动检测编码并设置
        response.encoding = response.apparent_encoding

        # 保存到E盘，处理中文路径
        save_path = 'E:\\萍乡学院.html'
        with open(save_path, 'w', encoding=response.encoding, errors='ignore') as f:
            f.write(response.text)
        print(f"页面已成功保存至：{save_path}")
    except requests.exceptions.RequestException as e:
        print(f"请求失败：{e}")
    except Exception as e:
        print(f"发生错误：{e}")


if __name__ == '__main__':
    crawl_pxc()